package com.rjkj.medicalwaste.utils

import com.rjkj.medicalwaste.utils.MD5Utils.MD5Encode
import java.util.*


object StringUtils {
    @JvmStatic
    fun isNullOrEmpty(string: String?):Boolean{
        return string == null || string.isEmpty()
    }
    @JvmStatic
    fun checkTagRealness(data: String): Boolean {
        if (data.length<2||data.length != 18) {
            return false
        }
        val isDoctorAndDepart = data.substring(0, 2)
        val mddataStr1: String = MD5Encode(isDoctorAndDepart, "UTF-8")
        val mddataStr2: String = MD5Encode(data.substring(2, 17), "UTF-8")
        return MD5Encode(mddataStr1 + mddataStr2, "UTF-8").substring(0, 1) == data.substring(17, 18)
    }

    @JvmStatic
    fun checkBoxQrCode(qrCode: String): Boolean {
        if (qrCode.isEmpty()) {
            return false
        }
        if (qrCode.length != 16) {
            return false
        }
        val m = qrCode.substring(7, 14)
        val l = qrCode.substring(14)
        return MD5Encode(m, null).toUpperCase(Locale.ROOT).substring(10, 12) == l
    }

}
